package com.system.outpatientsystem.controller;

import com.system.outpatientsystem.pojo.Category;
import com.system.outpatientsystem.pojo.Doctor;
import com.system.outpatientsystem.pojo.Result;
import com.system.outpatientsystem.pojo.User;
import com.system.outpatientsystem.service.DoctorService;
import com.system.outpatientsystem.utils.JwtUtils;
import com.system.outpatientsystem.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/doctor")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    @PostMapping("/login")
    public Result login(@RequestBody Doctor udoctor){
        //查询用户
        Doctor doctor = doctorService.findByPhone(udoctor.getPhone());
        System.out.println(doctor.getPhone());
        if (doctor == null){
            System.out.println("用户不存在");
            return Result.error("用户不存在");
        }
        //判断密码

        if (doctor.getPassword().equals(udoctor.getPassword())){
            //登录成功
            System.out.println("登录成功");

            return Result.success(doctor);
        }
        //密码错误
        System.out.println("密码错误");
        return Result.error("密码错误");
    }

    @GetMapping("/getCategory")
    public Result<List<Category>> getCategory(){
        //查询科室列表
        List<Category> list = doctorService.getCategory();
        return Result.success(list);
    }

    @PutMapping("/getDoctorsByOffice")
    public Result<List<Doctor>> getDoctorsByOffice(@RequestBody Map<String,String> par){
        String office=par.get("office");
        //按照科室获取医生列表
        System.out.println("选择的科室: "  + office);
        List<Doctor> list = doctorService.getDoctorsByOffice(office);
        return Result.success(list);
    }


}







